Type.registerNamespace("Telerik.Web.UI.Spell");
Telerik.Web.UI.Spell.SpellDialog=function(a){Telerik.Web.UI.Spell.SpellDialog.initializeBase(this,[a]);
this._clientParameters=null;
this._spell=null;
this._modeChangedHandler=null;
this._suggestionsDblClickHandler=null;
this._localization={};
this._spellProcessor=null;
this._contentDisplay=null;
this._serviceConfiguration=null;
this._serviceUrl=null;
this._windowClosingDelegate=null;
};
Telerik.Web.UI.Spell.SpellDialog.prototype={initialize:function(){Telerik.Web.UI.Spell.SpellDialog.callBaseMethod(this,"initialize");
this.initChildControls();
},dispose:function(){if(this._contentDisplay){this._contentDisplay.remove_modeChanged(this._modeChangedHandler);
this._modeChangedHandler=null;
this._contentDisplay.remove_suggestionsDblClick(this._suggestionsDblClickHandler);
this._suggestionsDblClickHandler=null;
}this._windowClosingDelegate=null;
Telerik.Web.UI.Spell.SpellDialog.callBaseMethod(this,"dispose");
},clientInit:function(a){this._suggestions.disabled=false;
this._suggestions.options.length=0;
this._suggestions.focus();
this._suggestions.disabled=true;
this.enableButton(this._cancel);
this.findChildElement("_TextContainer").innerHTML="";
this._clientParameters=a;
this._spell=this._clientParameters.spell;
this._textSource=this._clientParameters.textSource;
if(!this._textSource||!this._textSource.get_text){alert("This textsource does not support the get_text() method.");
return;
}var d=Telerik.Web.UI.Dialogs.CommonDialogScript.get_windowReference();
var c=d.BrowserWindow;
this._origFn=c.Function._validateParams;
try{c.Function._validateParams=new c.Function();
}catch(e){}Sys.Application.add_unload(Function.createDelegate(this,this.restoreFrameworkCode));
this._windowClosingDelegate=Function.createDelegate(this,this.prepareClose);
d.add_close(this._windowClosingDelegate);
this._textToCheck=this.escapeNewLines(this._textSource.get_text());
var b=this;
if(this._clientParameters.dictionaryLanguage){this.get_service().set_language(this._clientParameters.dictionaryLanguage);
}this.get_service().spellCheck(this._textToCheck);
},initChildControls:function(){var a=Telerik.Web.UI.Dialogs.CommonDialogScript.get_windowReference();
a.set_title(this.get_localization().Title);
this._suggestions=this.findChildElement("_Suggestions");
this._ignore=this.getConfiguredButton("_Ignore",this.ignoreHandler);
this._ignoreAll=this.getConfiguredButton("_IgnoreAll",this.ignoreAllHandler);
this._addCustom=this.getConfiguredButton("_AddCustom",this.addCustomHandler);
this._change=this.getConfiguredButton("_Change",this.changeHandler);
this._changeAll=this.getConfiguredButton("_ChangeAll",this.changeAllHandler);
this._undo=this.getConfiguredButton("_Undo",this.undoHandler);
this._cancel=this.getConfiguredButton("_Cancel",this.cancelHandler);
},ignoreHandler:function(){if(this._contentDisplay.get_editMode()){this._contentDisplay.switchMode();
}else{this._spellProcessor.ignore();
this.raiseOnClientWordIgnoredEvent(false);
this.moveForward();
}},ignoreAllHandler:function(){if(this._ignoreAll.disabled){return;
}this._spellProcessor.ignoreAll();
this.raiseOnClientWordIgnoredEvent(true);
this.moveForward();
},addCustomHandler:function(){if(this._addCustom.disabled){return;
}var b=this._spellProcessor.currentBadWord().wordString;
if(!confirm(this.get_localization()["AddWord1"]+b+this.get_localization()["AddWord2"])){return;
}this.disableAllButtons();
var a=this;
this.get_service().addCustomWord(b);
},changeHandler:function(){if(this._change.disabled){return;
}this.changeCurrentWord(this._contentDisplay.replacementWord());
},changeAllHandler:function(){if(this._changeAll.disabled){return;
}if(this._spellProcessor.allWordsFixed()){return;
}this._spellProcessor.changeAll(this._contentDisplay.replacementWord());
this.raiseOnClientWordCorrectedEvent(true);
this.moveForward();
},undoHandler:function(){if(this._undo.disabled){return;
}var a=this._spellProcessor.lastActionBadWordStartCharOffsets();
this._spellProcessor.undo();
this.raiseOnClientActionUndoneEvent(a);
this.processCurrentStep();
},cancelHandler:function(){if(this._cancel.disabled){return;
}this.closeDialog(this._spellProcessor&&this._spellProcessor.textChanged()&&confirm(this.get_localization()["Confirm"]));
},disableButton:function(a){Telerik.Web.UI.RadFormDecorator.set_enabled(a,false);
},enableButton:function(a){Telerik.Web.UI.RadFormDecorator.set_enabled(a,true);
},setButtonEnabled:function(a,b){if(b){this.enableButton(a);
}else{this.disableButton(a);
}},getConfiguredButton:function(a,b){var c=this.findChildElement(a);
if(c){$addHandlers(c,{click:b},this);
c.disabled=true;
}return c;
},findChildElement:function(a){return $get(this.get_id()+a);
},get_service:function(){if(this._service==null){this._service=$create(Telerik.Web.UI.SpellCheckService,null,null,null);
this._service.set_configuration(this.get_serviceConfiguration());
this._service.set_url(this.get_serviceUrl());
this._service.add_complete(Function.createDelegate(this,this.spellCheckResponseReceived));
}return this._service;
},changeCurrentWord:function(a){if(this._spellProcessor.allWordsFixed()){return;
}this._spellProcessor.change(a);
this.raiseOnClientWordCorrectedEvent(false);
this.moveForward();
},moveForward:function(){this._spellProcessor.moveToNextWord();
this.processCurrentStep();
},processCurrentStep:function(){if(!this._spellProcessor.allWordsFixed()){this.updateContent();
}else{this.closeDialog(true);
}},restoreFrameworkCode:function(){if(null!=this._origFn){var a=Telerik.Web.UI.Dialogs.CommonDialogScript.get_windowReference().BrowserWindow;
a.Function._validateParams=this._origFn;
this._origFn=null;
}},prepareClose:function(b){if(null!=this._windowClosingDelegate){var a=Telerik.Web.UI.Dialogs.CommonDialogScript.get_windowReference();
a.remove_close(this._windowClosingDelegate);
this._windowClosingDelegate=null;
this.restoreFrameworkCode();
}this.disableAllButtons();
this.raiseDialogClosingEvents();
if(this._spellProcessor){if(this._spellProcessor.allWordsFixed()){this._spell.set_spellChecked(true);
}if(b){this.applyChanges();
}this._spellProcessor=null;
}},closeDialog:function(a){this.prepareClose(a);
this._spell.raiseEvent("clientDialogClosing",Sys.EventArgs.Empty);
Telerik.Web.UI.Dialogs.CommonDialogScript.get_windowReference().close();
},spellCheckResponseReceived:function(c,a){if(a.AddCustomWord){var d=this._spellProcessor.currentBadWord().wordString;
this._spellProcessor.processCustomWordAddition();
this.raiseOnClientCustomWordAddedEvent(d);
this.processCurrentStep();
this.enableButton(this._cancel);
}else{var b={textToCheck:this._textToCheck,badWords:a.badWords,wordOffsets:a.wordOffsets};
this._spellProcessor=$create(Telerik.Web.UI.Spell.SpellProcessor,b,null,null);
if(!this._spellProcessor.allWordsFixed()){this.initContentDisplay();
this.updateContent();
}else{this.closeDialog(true);
}}},escapeNewLines:function(b){var a=b.replace(/\n/gi,"&nbsp;<telerikcr />");
a=a.replace(/\r/gi,"<teleriklf />");
return a;
},unEscapeNewLines:function(b){var a=b.replace(/(&nbsp;)?<telerikcr\s*\/>/gi,"\n");
var a=a.replace(/<teleriklf\s*\/>/gi,"\r");
return a;
},updateContent:function(){if(this._contentDisplay.get_editMode()){this._contentDisplay.switchMode();
}this._contentDisplay.showText(this._spellProcessor.currentErrorContent());
this.focusCurrentError();
this._contentDisplay.fillSuggestions(this._spellProcessor.currentSuggestions());
this.updateButtonStates();
},focusCurrentError:function(){var a=document.getElementById(this._spellProcessor.highlightedElementId());
if(a&&!this._contentDisplay.get_editMode()){this._contentDisplay.get_textContainer().scrollTop=a.offsetTop;
a.focus();
}},disableAllButtons:function(){this.disableButton(this._ignore);
this.disableButton(this._ignoreAll);
this.disableButton(this._change);
this.disableButton(this._changeAll);
this.disableButton(this._undo);
this.disableButton(this._cancel);
if(this._addCustom){this.disableButton(this._addCustom);
}},initContentDisplay:function(){this._modeChangedHandler=Function.createDelegate(this,this.contentDisplay_modeChanged);
this._suggestionsDblClickHandler=Function.createDelegate(this,this.contentDisplay_suggestionsDblClick);
var a={localization:this.get_localization(),textContainer:this.findChildElement("_TextContainer"),textEditor:this.findChildElement("_TextEditor"),suggestions:this._suggestions};
var b={modeChanged:this._modeChangedHandler,suggestionsDblClick:this._suggestionsDblClickHandler};
if(!this._contentDisplay){this._contentDisplay=$create(Telerik.Web.UI.Spell.ContentDisplay,a,b,null);
}this._contentDisplay.focus();
},updateButtonStates:function(){var a=this._spellProcessor.currentSuggestions().length>0;
this.enableButton(this._ignore);
this.setButtonEnabled(this._ignoreAll,!this._contentDisplay.get_editMode());
this.setButtonEnabled(this._undo,this._spellProcessor.currentUndoAction()!=null);
this.setButtonEnabled(this._change,this._contentDisplay.get_editMode()||a);
this.setButtonEnabled(this._changeAll,!this._contentDisplay.get_editMode()&&a);
if(this._addCustom!=null){this.setButtonEnabled(this._addCustom,!this._contentDisplay.get_editMode());
}this._ignore.innerHTML=this._contentDisplay.get_editMode()?this.get_localization()["UndoEdit"]:this.get_localization()["Ignore"];
},contentDisplay_modeChanged:function(a,b){var c="";
if(b.editMode){c=this._spellProcessor.currentBadWord().wordString;
}else{c=this._spellProcessor.currentErrorContent();
}this.updateButtonStates();
this._contentDisplay.showText(c);
this.focusCurrentError();
},contentDisplay_suggestionsDblClick:function(a,b){if(this._spellProcessor.currentSuggestions().length>0){this.changeCurrentWord(b.selectedValue);
}else{alert(this.get_localization()["Nosuggestions"]);
}},applyChanges:function(){this._textSource.set_text(this.unEscapeNewLines(this._spellProcessor._textToCheck));
},raiseDialogClosingEvents:function(){if(this._spellProcessor&&this._spellProcessor.allWordsFixed()){var a={suppressCompleteMessage:false};
this._spell.raiseEvent("clientCheckFinished",a);
if(!a.suppressCompleteMessage){alert(this.get_localization()["SpellCheckComplete"]);
}}else{this._spell.raiseEvent("clientCheckCancelled",Sys.EventArgs.Empty);
}},raiseOnClientWordCorrectedEvent:function(b){var c=this._spellProcessor.currentBadWord();
var a={originalWord:c.originalWordString,newWord:c.wordString,offsets:this._spellProcessor.lastActionBadWordStartCharOffsets(),changeAll:b};
this._spell.raiseEvent("clientWordCorrected",a);
},raiseOnClientWordIgnoredEvent:function(c){var b=this._spellProcessor.currentBadWord();
var a={ignoreWord:b.originalWordString,offsets:this._spellProcessor.lastActionBadWordStartCharOffsets(),ignoreAll:c};
this._spell.raiseEvent("clientWordIgnored",a);
},raiseOnClientActionUndoneEvent:function(c){var b=this._spellProcessor.currentBadWord();
var a={originalWord:b.originalWordString,offsets:c};
this._spell.raiseEvent("clientActionUndone",a);
},raiseOnClientCustomWordAddedEvent:function(b){var a={customWord:b};
this._spell.raiseEvent("clientCustomWordAdded",a);
},get_language:function(){return this._language;
},set_language:function(a){this._language=a;
},get_localization:function(){return this._localization;
},set_localization:function(a){this._localization=a;
},get_serviceUrl:function(){return this._serviceUrl;
},set_serviceUrl:function(a){this._serviceUrl=a;
},get_serviceConfiguration:function(){return this._serviceConfiguration;
},set_serviceConfiguration:function(a){this._serviceConfiguration=a;
}};
Telerik.Web.UI.Spell.SpellDialog.registerClass("Telerik.Web.UI.Spell.SpellDialog",Telerik.Web.UI.RadWebControl,Telerik.Web.IParameterConsumer);
Telerik.Web.UI.Spell.SpellProcessorActions=function(){throw Error.invalidOperation();
};
Telerik.Web.UI.Spell.SpellProcessorActions.prototype={Change:0,ChangeAll:1,Ignore:2,IgnoreAll:4,AddCustom:8};
Telerik.Web.UI.Spell.SpellProcessorActions.registerEnum("Telerik.Web.UI.Spell.SpellProcessorActions",false);
Telerik.Web.UI.Spell.SpellProcessor=function(){Telerik.Web.UI.Spell.SpellProcessor.initializeBase(this);
this._textToCheck=null;
this._badWords=null;
this._wordOffsets=null;
this._currentBadWordIndex=0;
this._undoActions=[];
this._surroundingWordsCount=10;
};
Telerik.Web.UI.Spell.SpellProcessor.prototype={initialize:function(){Telerik.Web.UI.Spell.SpellProcessor.callBaseMethod(this,"initialize");
},dispose:function(){Telerik.Web.UI.Spell.SpellProcessor.callBaseMethod(this,"dispose");
},moveToNextWord:function(){var a=this.nextBadWordIndex();
if(a<0){return;
}this.set_currentBadWordIndex(a);
},moveToPreviousWord:function(){this.set_currentBadWordIndex(this.nextBadWordIndex(0));
},nextBadWordIndex:function(a){if(typeof(a)=="undefined"){a=this.get_currentBadWordIndex();
}for(var b=a;
b<this._badWords.length;
b++){if(this.getBadWord(b).originalWordString==null){return b;
}}return -1;
},allWordsFixed:function(){return this.nextBadWordIndex()<0;
},currentErrorContent:function(){var a=this.currentBadWord();
return this.startString(this.get_currentBadWordIndex(),true)+"<a style='border-bottom: 1px dotted red;font-weight: bold;' id="+this.highlightedElementId()+">"+a.wordString+"</a>"+this.endString(this.get_currentBadWordIndex(),true);
},highlightedElementId:function(){return"spell_highlight_"+this.currentBadWord().wordString;
},startString:function(b,e){var d=0;
var a=this.getBadWord(b);
if(e&&(a.textOffset>this._surroundingWordsCount)){var c=a.textOffset-this._surroundingWordsCount;
d=this._wordOffsets[c];
}return this._textToCheck.substring(d,this.wordStartCharIndex(b));
},endString:function(b,e){var c=this._textToCheck.length;
var a=this.getBadWord(b);
if(e&&(this._wordOffsets.length>a.textOffset+this._surroundingWordsCount)){var d=a.textOffset+this._surroundingWordsCount;
c=this._wordOffsets[d];
}return this._textToCheck.substring(this.wordEndCharIndex(b),c);
},wordStartCharIndex:function(a){return this._wordOffsets[this.wordOffset(a)];
},wordEndCharIndex:function(a){return this.wordStartCharIndex(a)+this.getBadWord(a).wordString.length;
},getBadWord:function(a){return this._badWords[a];
},currentBadWord:function(){return this.getBadWord(this.get_currentBadWordIndex());
},wordOffset:function(a){return this.getBadWord(a).textOffset;
},currentWordOffset:function(){return this.currentBadWord().textOffset;
},currentSuggestions:function(){return this.currentBadWord().suggestionsString;
},ignore:function(){this.changeWord(this.currentBadWord().wordString,Telerik.Web.UI.Spell.SpellProcessorActions.Ignore);
},ignoreAll:function(){this.changeAllWords(this.currentBadWord().wordString,Telerik.Web.UI.Spell.SpellProcessorActions.IgnoreAll);
},change:function(a){this.changeWord(a,Telerik.Web.UI.Spell.SpellProcessorActions.Change);
},changeAll:function(a){this.changeAllWords(a,Telerik.Web.UI.Spell.SpellProcessorActions.ChangeAll);
},processCustomWordAddition:function(){var c=this.sameWordStringBadWordIndexes();
for(var b=c.length-1;
b>=0;
b--){var a=c[b];
this._badWords.splice(a,1);
}this.moveToNextWord();
},changeWord:function(b,c){var a=[this.get_currentBadWordIndex()];
this.processChange(a,b,false,c);
this.registerUndoStep(a);
},changeAllWords:function(b,c){var a=this.sameWordStringBadWordIndexes();
this.processChange(a,b,false,c);
this.registerUndoStep(a);
},changeText:function(a,b){this._textToCheck=this.startString(a,false)+b+this.endString(a,false);
},offsetsByBadWordIndexes:function(a){var c=[];
for(var b=0;
b<a.length;
b++){c[c.length]=this.wordOffset(a[b]);
}return c;
},lastActionBadWordOffsets:function(){var a=this.currentUndoAction();
return this.offsetsByBadWordIndexes(a);
},lastActionBadWordStartCharOffsets:function(){var c=[];
var a=this.lastActionBadWordOffsets();
for(var b=0;
b<a.length;
b++){c[c.length]=this._wordOffsets[a[b]];
}return c;
},sameWordStringBadWordIndexes:function(){var c=this.currentBadWord().wordString;
var b=[this.get_currentBadWordIndex()];
for(var a=this.get_currentBadWordIndex()+1;
a<this._badWords.length;
a++){if(this.getBadWord(a).wordString==c){b[b.length]=a;
}}return b;
},undo:function(){var b=this.currentUndoAction();
var a=this.getBadWord(b[0]).originalWordString;
this.processChange(b,a,true);
this.unregisterUndoStep();
this.moveToPreviousWord();
},correctWord:function(a,b,c){if(this.getBadWord(a).originalWordString){return;
}var d=this.getBadWord(a);
d.originalWordString=d.wordString;
d.wordString=b;
d.correctionAction=c;
},restoreWord:function(a){var b=this.getBadWord(a);
b.wordString=b.originalWordString;
b.originalWordString=null;
b.correctionAction=null;
},processChange:function(a,d,f,e){for(var c=0;
c<a.length;
c++){var b=a[c];
var h=this.getBadWord(b);
var g=d.length-h.wordString.length;
this.adjustOffsetsAfterChangedWord(h,g);
this.changeText(b,d);
if(f){this.restoreWord(b);
}else{this.correctWord(b,d,e);
}}},adjustOffsetsAfterChangedWord:function(b,c){for(var a=b.textOffset+1;
a<this._wordOffsets.length;
a++){this._wordOffsets[a]+=c;
}},currentUndoAction:function(){if(this._undoActions.length==0){return null;
}return this._undoActions[this._undoActions.length-1];
},registerUndoStep:function(a){this._undoActions[this._undoActions.length]=a;
},unregisterUndoStep:function(){this._undoActions=this._undoActions.slice(0,-1);
},textChanged:function(){for(var a=0;
a<this.get_currentBadWordIndex();
a++){var b=this.getBadWord(a).correctionAction;
if(b==Telerik.Web.UI.Spell.SpellProcessorActions.Change||b==Telerik.Web.UI.Spell.SpellProcessorActions.ChangeAll){return true;
}}return false;
},get_currentBadWordIndex:function(){return this._currentBadWordIndex;
},set_currentBadWordIndex:function(a){this._currentBadWordIndex=a;
},get_textToCheck:function(){return this._textToCheck;
},set_textToCheck:function(a){this._textToCheck=a;
},get_badWords:function(){return this._badWords;
},set_badWords:function(a){this._badWords=a;
},get_wordOffsets:function(){return this._wordOffsets;
},set_wordOffsets:function(a){this._wordOffsets=a;
}};
Telerik.Web.UI.Spell.SpellProcessor.registerClass("Telerik.Web.UI.Spell.SpellProcessor",Sys.Component);
Telerik.Web.UI.Spell.ContentDisplay=function(){Telerik.Web.UI.Spell.ContentDisplay.initializeBase(this);
this._editMode=false;
this._textContainer=null;
this._textEditor=null;
this._suggestions=null;
this._localization=null;
};
Telerik.Web.UI.Spell.ContentDisplay.prototype={initialize:function(){Telerik.Web.UI.Spell.ContentDisplay.callBaseMethod(this,"initialize");
$addHandlers(this.get_textContainer(),{click:this.switchMode},this);
this.get_suggestions().disabled=false;
$addHandlers(this.get_suggestions(),{dblclick:this.suggestionsDblClick},this);
},dispose:function(){$clearHandlers(this.get_suggestions());
$clearHandlers(this.get_textContainer());
this._textContainer=null;
this._textEditor=null;
this._suggestions=null;
this._localization=null;
Telerik.Web.UI.Spell.ContentDisplay.callBaseMethod(this,"dispose");
},showText:function(a){if(this.get_editMode()){this.get_textEditor().value=a;
}else{this.get_textContainer().innerHTML=a;
}},focus:function(){if(this.get_editMode()){this.get_textEditor().focus();
}else{if(this.get_suggestions().disabled){this.get_suggestions().disabled=false;
}this.get_suggestions().focus();
}},switchMode:function(){this.set_editMode(!this.get_editMode());
if(this.get_editMode()){this.get_textContainer().style.display="none";
this.get_textEditor().style.display="block";
this.get_textEditor().focus();
this.get_suggestions().disabled=true;
}else{this.get_textContainer().style.display="";
this.get_textEditor().style.display="none";
this.get_suggestions().disabled=false;
}this.raiseEvent("modeChanged",{editMode:this.get_editMode()});
this.focus();
},replacementWord:function(){if(this.get_editMode()){return this.get_textEditor().value;
}else{return this.selectedSuggestion();
}},selectedSuggestion:function(){return this.get_suggestions().options[this.get_suggestions().selectedIndex].value;
},fillSuggestions:function(a){this.clearSuggestions();
if(a.length>0){for(var b=0;
b<a.length;
b++){this.addSuggestion(a[b]);
}}else{this.addSuggestion(this.get_localization()["Nosuggestions"]);
}this.get_suggestions().selectedIndex=0;
},clearSuggestions:function(){this.get_suggestions().options.length=0;
},addSuggestion:function(a){this.get_suggestions().options[this.get_suggestions().options.length]=new Option(a,a);
},suggestionsDblClick:function(){this.raiseEvent("suggestionsDblClick",{selectedValue:this.selectedSuggestion()});
},raiseEvent:function(b,c){var a=this.get_events().getHandler(b);
if(a){if(!c){c=Sys.EventArgs.Empty;
}a(this,c);
}},add_modeChanged:function(a){this.get_events().addHandler("modeChanged",a);
},remove_modeChanged:function(a){this.get_events().removeHandler("modeChanged",a);
},add_suggestionsDblClick:function(a){this.get_events().addHandler("suggestionsDblClick",a);
},remove_suggestionsDblClick:function(a){this.get_events().removeHandler("suggestionsDblClick",a);
},set_localization:function(a){this._localization=a;
},get_localization:function(){return this._localization;
},set_suggestions:function(a){this._suggestions=a;
},get_suggestions:function(){return this._suggestions;
},set_textContainer:function(a){this._textContainer=a;
},get_textContainer:function(){return this._textContainer;
},set_editMode:function(a){this._editMode=a;
},get_editMode:function(){return this._editMode;
},set_textEditor:function(a){this._textEditor=a;
},get_textEditor:function(){return this._textEditor;
}};
Telerik.Web.UI.Spell.ContentDisplay.registerClass("Telerik.Web.UI.Spell.ContentDisplay",Sys.Component);
